package licode.unisop.client.utils;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.Set;

/**
 * 过滤掉不处理的地址
 *
 * @author WR
 * @since 2016/6/15 16:36
 */
@Component
public class SopUriUtil {
    private final Set<String> filterUrls = new HashSet<>();

    @PostConstruct
    public void init() {
        filterUrls.add("/uni-auth/v1/token/credential");
        filterUrls.add("/uni-auth/v1/token/valid");
        filterUrls.add("/uni-api/v1/auth/captcha/code");
        filterUrls.add("/uni-api/v1/auth/authorize");
        filterUrls.add("/uni-api/v1/auth/authorize-direct");
        filterUrls.add("/uni-api/v1/auth/token");
        filterUrls.add("/uni-api/v1/auth/login");
        filterUrls.add("/uni-api/v1/auth/login-direct");
        filterUrls.add("/uni-api/v1/auth/query/platform-token");
        filterUrls.add("/uni-api/v1/platform/query/lookup");
    }

    public boolean isFilter(String url) {
        if (url.startsWith(SopAuthConst.AUTH_UI_FILTER) ||
                url.startsWith(SopAuthConst.USER_INTERNAL) ||
                url.startsWith(SopAuthConst.PLAT_INTERNAL) ||
                url.startsWith(SopAuthConst.CENTER_INTERNAL)) {
            return true;
        }

        if (filterUrls.contains(url)) {
            return true;
        }

        if ("/favicon.ico".compareToIgnoreCase(url) == 0) {
            return true;
        }

        if (url.endsWith(".css") || url.endsWith(".png") ||
                url.endsWith(".jpg") || url.endsWith(".map")) {
            return true;
        }

        return false;
    }
}
